package com.xk.meeting.dao;

import com.xk.meeting.entity.Admin;
import com.xk.meeting.utils.ConnectionUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class AdminDaoImpl implements AdminDao{
    private JdbcTemplate template = new JdbcTemplate(ConnectionUtils.getDataSource());
    @Override
    public Admin login(String username, String password) {
        String sql = "select * from admin where username = ? and password = ?";
        try {
            return template.queryForObject(sql,new BeanPropertyRowMapper<Admin>(Admin.class),username,password);
        } catch (DataAccessException e){
            return null;
        }
    }

    @Override
    public int update(int id, String password) {
        String sql = "update admin set password = ? where id = ?";
        return template.update(sql,password,id);
    }
}
